<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"	/>
    <title>抽签系统</title>
    <style type="text/css">
        .container{background-color:#ffff99;
            margin-top:10px;margin-left:300px;margin-right:300px;width:auto;height:auto;}
    </style>
    <script>
        var num = 0;
        var arr = new Array();
        var vis = new Array();
        var mark = new Array();
        var c = 0;
        var k = 0;
        var t;
        var input;


        //for(var i = 0; i < 19; i++)
        //	vis[i] = i+1;

        var cont = 0;
        while(1)
        {

            var input=parseInt(Math.random()*$name+1);
            if(!mark[input])
            {
                mark[input] = 1;
                vis[cont++] = input;
            }
            if(cont == $name)
                break;
        }

        function timedCount()
        {

            document.getElementById('txt').value = c;
            k = k+1;
            k = k%(vis.length);
            c = vis[k];

            t = setTimeout("timedCount()",100)
        }

        function stopCount()
        {

            clearTimeout(t);
            input = document.getElementById('txt').value
        }

        function Random()
        {

            //tt = parseInt(Math.random()*19+1);
            var draw = document.getElementById("display");
            num++;
            arr.push(input);
            draw.innerHTML = draw.innerHTML + "<h1>第"+num+"组抽中："+input+"<br/></h1>";
            var tmp = new Array();
            tmp.length = 0;
            var cnt = 0;
            for(var i = 0; i < vis.length; i++)
            {
                if(vis[i] != tt)
                {
                    tmp[cnt] = vis[i];
                    cnt = cnt+1;
                }
            }
            vis.length = 0;
            for(var i = 0; i < tmp.length; i++)
            {
                vis[i] = tmp[i];
            }
            document.getElementById("count").innerHTML = arr.length;
            if(arr.length == $name){
                alert("已经抽完!");
            }
        }

        function Clear(){
            arr = null;
            arr = new Array();

            mark = new Array();
            var cont = 0;
            while(1)
            {
                var input = parseInt(Math.random()*$name+1);
                if(!mark[input])
                {
                    mark[input] = 1;
                    vis[cont++] = input;
                }
                if(cont == $name)
                    break;
            }

            //for(var i = 0; i < 19; i++)
            //	vis[i] = i+1;

            k = 0;
            num = 0;
            c = 0;
            clearTimeout(t);
            document.getElementById('txt').value=  "0";
            document.getElementById("count").innerHTML = "0";
            document.getElementById("display").innerHTML = "";
        }
    </script>
</head>

<body>

<div class = "container">
    <input type = "text" style = "border:0px;text-align:center;font-size:60px;background-color:#ffff99;" id = "txt">
    <br>
    <input type="text" id="name"/>
    <br>
    <font size = "20"> 目前已经抽出<span id = "count"> 0 </span>个!</font>
    <br>
    <input type = "button" style = 'font-size:30px' value = "开始" onclick = "timedCount(); "/>  
    <input type = "button" style = 'font-size:30px' value = "停止" onClick = "stopCount();Random();">  
    <input type = "button" style = 'font-size:30px' value = "清空" onclick = "Clear();"/>
    <br>
    <br>
    <span id = "display"></span>
    <br>
</div>

</body>
</html>